package ke06;

import java.io.File;
import java.util.Arrays;

import javax.xml.bind.JAXB;
import javax.xml.bind.JAXBException;

public class GenerateXML {
	
	public static void main(String[] args) throws JAXBException {
		
		Student sepp = new Student();
		sepp.setName("Sepp");
		sepp.setStudyID(1234);
		sepp.setDepartment("Informatik");
		
//		JAXBContext context = JAXBContext.newInstance(Student.class);
//		Marshaller m = context.createMarshaller();
//		m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
//		m.marshal(sepp, System.out);
		
		Student anne = new Student();
		anne.setName("Anne");

		University uni = new University();
		uni.setStudents(Arrays.asList(sepp,anne));

		File file = new File("university.xml");
		JAXB.marshal(uni,file);

		University uni2 = JAXB.unmarshal(file,University.class);
		System.out.println(uni2.getStudents().get(1).getName()); // Anne
	}
}
